package p2pscrabble;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;


public class Dictionary {

	FileReader in_file = null;
	BufferedReader in = null;

	public boolean checkWordExist(String word) {
		word = word.toUpperCase();
		char firstLetter = word.charAt(0);
		int wordLength = word.length();

		File f = new File(".\\dict\\" + firstLetter + wordLength + ".txt");

		try {
			in_file = new FileReader(f);
			in = new BufferedReader(in_file);
			String line = in.readLine();

			while (!line.equals("") && line != null
					&& line.toUpperCase().compareTo(word) <= 0) {
				if (line.toUpperCase().equals(word))
					return true;
				line = in.readLine();
			}

		} catch (FileNotFoundException e) {
		} catch (NullPointerException e) {
		} catch (IOException e) {
			e.printStackTrace();
		}

		return false;
	}
}
